#include <stdio.h>
#include <stdlib.h>

#define true 1
#define false 0
typedef int bool;

bool aTrue, bTrue;

int judge (int m, int n, int p)
{

    if (aTrue) return 0;
    if (m == 1 && n == 1) { /* a and b tell truth */
        aTrue = true; return 0; /* aTrue win */
    }
    if (n == 1) bTrue = true; /* bTrue win */
    while (p > 1) {
        if (m % p == 0) judge(m/p, n, p-1); /* m div p */
        if (n % p == 0) judge(m, n/p, p-1); /* n div p */
        p--;
    }

    return 0;
}

int main (int argc, char const* argv[])
{
    int a, b, t;

    while (scanf("%d %d", &a, &b) != EOF) {
        if (a < b) { /* assert a > b */
            t = a; a = b; b = t;
        }

        aTrue = false; bTrue = false;
        judge(a, b, 100);
        if (!aTrue && bTrue) {
            printf("%d\n", b);
        } else {
            printf("%d\n", a);
        }
    }

    return 0;
}
